#!/usr/bin/php -d mysqlnd.net_read_timeout=3600
<?php
set_include_path("../include");
require("header.inc.php");

if (empty($argv[1])) {
	echo "Usage: $argv[0] [-f|--force] userID\n";
	exit(1);
}

$userID = (int) $argv[1];
$username = Zotero_Users::getUsername($userID, true);

$opts = getopt('f', ['force']);
if (!isset($opts['f']) && !isset($opts['force'])) {
	echo "Really delete user '$username'? Type 'yes' to continue: ";
	$handle = fopen ("php://stdin","r");
	$line = fgets($handle);
	if (trim($line) != 'yes') {
		echo "Aborting\n";
		exit;
	}
}

$deleted = Zotero_Users::deleteUser($userID);
if ($deleted) {
	echo "User '$username' deleted\n";
}
else {
	echo "Not deleted\n";
}
